package com.tarena.lbs.basic.web.controller;

import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.basic.web.service.IAreaService;
import com.tarena.lbs.common.basic.converter.AreaConverter;
import com.tarena.lbs.pojo.basic.bo.AreaBO;
import com.tarena.lbs.pojo.basic.vo.AreaVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(value = "area", tags = "区域")
@Slf4j
@Validated
@RestController
@RequestMapping("/admin/basic/area")
public class AreaController {

    @Resource
    private IAreaService areaService;

    @Resource
    private AreaConverter areaConverter;

    @GetMapping("/tree")
    @ApiOperation(value = "返回三级城市树")
    public Result<List<AreaVO>> buildAreaTree() {
        List<AreaBO> result = areaService.queryAreaData();
        return new Result<>(areaConverter.boList2VoList(result));
    }

    @GetMapping("queryList")
    @ApiOperation(value = "查询全部省数据[不分页]")
    public Result<List<AreaVO>> queryList() {
        List<AreaBO> result = areaService.queryProvinceList();
        return new Result<>(areaConverter.boList2VoList(result));
    }

    @GetMapping("{parentId}/children")
    @ApiOperation(value = "根据父级id查询下级")
    public Result<List<AreaVO>> backCategoryChildren(@PathVariable Long parentId) {
        List<AreaBO> result = areaService.findByParentId(parentId);
        return new Result<>(areaConverter.boList2VoList(result));
    }

}
